<admintpl file="header" />
</head>
<body>
	<div class="wrap js-check-wrap">
		<ul class="nav nav-tabs">
			<li class="active"><a href="{:U('Admin/Live/index')}">直播列表</a></li>
			<li><a href="{:U('Admin/Live/add')}">添加直播</a></li>
		</ul>
		<form class="well form-search" id="query_form" method="post" action="{:U('Admin/Live/index')}">
			名称： 
			<input type="text" name="name" style="width: 120px;" value="{$formParam.name}" placeholder="直播名称...">
			类型：
			<select class="select_2" id="category" name="category" style="width: 90px;">
				<option value='-1'>全部</option>
				<option value='1' <if condition="$formParam.category eq 1"> selected </if>>视频直播</option>
				<option value='2' <if condition="$formParam.category eq 2"> selected </if>>VR直播</option>
				<option value='3' <if condition="$formParam.category eq 3"> selected </if>>图文直播</option>
				<option value='4' <if condition="$formParam.category eq 4"> selected </if>>视频加图文直播</option>
				<option value='5' <if condition="$formParam.category eq 5"> selected </if>>VR加图文直播</option>
				<!--<option value='6' <if condition="$formParam.category eq 6"> selected </if>>录播</option>-->
			</select>
			状态： 
			<select class="select_2" name="status" style="width: 90px;">
				<option value='-1'>全部</option>
				<option value='3' <if condition="$formParam.status eq 3"> selected </if>>未开始</option>
				<option value='2' <if condition="$formParam.status eq 2"> selected </if>>直播结束</option>
				<option value='4' <if condition="$formParam.status eq 4"> selected </if>>正在直播</option>
				<option value='5' <if condition="$formParam.status eq 5"> selected </if>>直播回顾</option>
			</select>
			<input type="button" name="query_form_btn" id="queryBtn" data-action="{:U('Admin/Live/index')}" class="btn btn-primary" value="查询" />
		</form>
		<form class="js-ajax-form" action="" method="post">
		<table class="table table-hover table-bordered">
			<thead>
				<tr>
					<th>名称</th>
					<th>类型</th>
					<th>开始时间</th>
					<th>URL</th>
					<th>排序日期</th>
					<th>状态</th>
					<th>观看人数</th>
					<if condition="$user_can_show_count eq 1"><th>真实观看人数</th></if>
					<th>权重</th>
					<th>创建者</th>
					<th>操作</th>
					<th>打赏列表</th>
				</tr>
			</thead>
			<tbody>
				<php>
					 $status = array("2"=>'直播结束',"3"=>'未开始',"4"=>'正在直播',"5"=>'直播回顾');
				</php>
				<foreach name="data" item="vo">
				<tr>
					<td>{$vo.name}</td>
					<td><if condition="$vo.category eq 1">视频直播</if>
					<if condition="$vo.category eq 2">VR直播</if>
					<if condition="$vo.category eq 3">图文直播</if>
					<if condition="$vo.category eq 4">视频加图文直播</if>
					<if condition="$vo.category eq 5">VR加图文直播</if>
					<if condition="$vo.category eq 6">录播</if>
					</td>
					<td>{$vo['start_time']}</td>
					<td>id={$vo['live_id']}&type=live
					<a style="float:right;" class="link_url" data-clipboard-text="id={$vo['live_id']}&type=live" title="id={$vo['live_id']}&type=live" href="javascript:;" >复制</a>
					</td>
					<td>
					<!-- <if condition="$vo.red_score neq null">
					{$vo.red_score}（{$vo.red_competitor}）：{$vo.blue_score}（{$vo.blue_competitor}）
					</if> -->
					<!-- 直播列表刷新 排序时间 -->
					{$vo['refresh_time']}
						<?php if($admin_id == 1){?>
					<input type="button" id="refresh" value="刷新" onclick="refresh_news('<?php echo $vo['live_id'];?>')" class="btn btn-primary" style="float:right;">
						<?php } ?>
					</td>
					<td>{$status[$vo['status']]}</td>
					<td><input type="text" name="weight" id="weight{$vo.live_id}" value="{$vo.play_count}" disabled="disabled" size="2"  class="input_edit">
						<if condition="$_SESSION['ADMIN_ID'] eq 1">
                        	<a id="edit_weight_{$vo.live_id}" href='javascript:void(0);' onclick="update_live_count('{$vo.live_id}','live')" class="edit_sub">修改</a>
						</if>
                        <input type="hidden" name="old_weight" id="old_weight_{$vo.live_id}" value="{$vo.play_count}">
                    </td>
                    <if condition="$user_can_show_count eq 1">
                    	<td>{$vo.true_play_count}</td>
                    </if>
					<!-- <td>{$vo['weight']}</td> -->
					<td><input type="text" name="live_weight" id="live_weight{$vo.live_id}" value="{$vo.weight}" disabled="disabled" size="2"  class="live_input_edit">
                        <a id="live_edit_weight_{$vo.live_id}" href='javascript:void(0);' onclick="update_weight('{$vo.live_id}','live')" class="live_edit_sub">修改</a>
                        <input type="hidden" name="live_old_weight" id="live_old_weight_{$vo.live_id}" value="{$vo.weight}">
                    </td>
                    <td>{$vo.creator_name}</td>
					<td>
					<if condition="in_array($vo['category'],array(3,4,5))"> 
						<a href='{:U("Admin/LiveGraphic/live_panel", array("live_id"=>$vo["live_id"]))}'>直播员面板</a>
					</if>
						   <if condition="$vo.type eq 2">
								<if condition="$vo.status neq 3">
									<a class="set_result" data-id="{$vo.live_id}" data-red-id="{$vo.red_competitor_id}" data-blue-id="{$vo.blue_competitor_id}" href='{:U("Admin/Live/set_result", array("live_id"=>$vo["live_id"]))}'>更新比分</a>
								</if>
						   </if>

						   <a href='{:U("Admin/Live/edit", array("live_id"=>$vo["live_id"]))}'>编辑</a>
						   <if condition="$vo.status neq 3">
								<a href='{:U("Admin/Live/view", array("live_id"=>$vo["live_id"]))}' >详情</a>
						   </if>

						   <if condition="$vo.status neq 4 and $admin_id eq 1">
								<a href='{:U("Admin/Live/delete", array("live_id"=>$vo["live_id"]))}' class="js-ajax-dialog-btn">删除</a>
						   </if>
						   <a href='{:U("Admin/Live/news_relation", array("live_id"=>$vo["live_id"]))}'>相关文章</a>
							<!--<if condition="$vo.is_fast eq 0">--><!--</if>-->
							<a href='{:U("Admin/Live/direct_manage", array("live_id"=>$vo["live_id"],"is_fast"=>$vo["is_fast"]))}'>导播管理</a>

						   <if condition="$vo.status neq 3">
								<a class="set_status" data-id="{$vo.live_id}" data-status="{$vo.status}" href='{:U("Admin/Live/set_status", array("live_id"=>$vo["live_id"]))}'>更新状态</a>
						   </if>
							<if condition="$vo.quiz_status eq 1">
								<a href='{:U("Admin/Guest/index", array("live_id"=>$vo["live_id"]))}'>竞猜管理</a>
							</if>
							<if condition="$vo.is_props neq 0">
								<a href='{:U("Admin/Prop/index", array("live_id"=>$vo["live_id"]))}'>打赏管理</a>
							</if>
					</td>
					<td><a href="{:U('Admin/Live/live_reward_list',array( 'live_id'=>$vo['live_id']))}" >{$vo.hw_money_total}汇闻币</a></td>
				</tr>
				</foreach>
			</tbody>
		</table>
		</form>
		<div class="pagination">{$page}</div>
	</div>
	<script src="__PUBLIC__/js/common.js"></script>
	<script type="text/javascript" src="__PUBLIC__/js/ueditor/third-party/zeroclipboard/ZeroClipboard.min.js"></script>
	<script src="__PUBLIC__/js/layer/layer.js"></script>
	<script>
	$(document).ready(function(){
		$('input[name="query_form_btn"]').click(function(){
			 $('#query_form').attr('action', $(this).attr('data-action'));
			 $('#query_form').submit();
		});
		
		var clip = new ZeroClipboard($("td .link_url"));
		clip.on("aftercopy", function(e){
			layer.msg('复制成功！');
		    //alert('复制成功！');
		});
		$('#typeId').val({$formParam.typeId});
		
		$('.set_result').click(function(e){
			e.preventDefault();
			$_this = this;
			var live_id = $($_this).attr('data-id');
			var red_competitor_id = $($_this).attr('data-red-id');
			var blue_competitor_id = $($_this).attr('data-blue-id');
			
			$.getJSON('{:U("Admin/Live/get_competitor")}&red_competitor_id='+red_competitor_id+'&blue_competitor_id='+blue_competitor_id).done(function (data) {
	            if (data.state === 'success') {
	            	var href = $($_this).prop('href');
	            	var contentHtml = "<div style='width:220px;height:100px;padding:0px 10px;'><div style='width:80px;float:left;text-align:center;'><div style='width:80px; height:80px; border-radius:50%; overflow:hidden;'><img src="+
	            	                  data.info.red.avatar+" style='width:80px;height:80px;'></div><span>"+
	            	                  data.info.red.real_name+"</span></div><div style='width:80px;float:right;text-align:center;'><div style='width:80px; height:80px; border-radius:50%; overflow:hidden;'><img src="+
	            	                  data.info.blue.avatar+" style='width:80px;height:80px;'></div><span>"+
	            	                  data.info.blue.real_name+"</span></div><div style='width:220px;float:left;margin-top:10px;text-align:center;'><input id='red_score' style='width:75px;'><span style='font-family:Bold;font-weight:900;width:20px;margin-left:20px;margin-right:20px;'>：</span><input id='blue_score' style='width:75px;'></div></div>";
	            	
	    			art.dialog({
	                    title: "更新比分",
	                    icon: '',
	                    content: contentHtml,
	                    close: function () {
	                        $_this.focus(); //关闭时让触发弹窗的元素获取焦点
	                        return true;
	                    },
	                    okVal:"确定",
	                    ok: function () {
	                    	var red_score = $('#red_score').val();
	                    	var blue_score = $('#blue_score').val();
	                    	if(red_score == '' || blue_score == ''){
	                    		layer.msg('请输入比赛结果！');
	                    		return false;
	                    	}
	                    	
	                    	var g = /^[1-9]*[1-9][0-9]*$/;
	                        if(!g.test(red_score)){
	                        	layer.msg('请输入整数！');
	                    		return false;
	                        }
	                        if(!g.test(blue_score)){
	                        	layer.msg('请输入整数！');
	                    		return false;
	                        }
	                    	
	                    	art.dialog({
	                            title: false,
	                            icon: 'question',
	                            content: '您确定要将比分设定为 ' + red_score+ '（' + data.info.red.real_name + '）：' + blue_score + '（' + data.info.blue.real_name+'）吗？',
	                            close: function () {
	                            },
	                            okVal:"确定",
	                            ok: function () {
	                            	$.getJSON(href+'&live_id=' + live_id+'&red_score='+red_score+'&blue_score='+blue_score).done(function (data) {
	                                    if (data.state === 'success') {
	                                        if (data.referer) {
	                                            location.href = data.referer;
	                                        } else {
	                                            reloadPage(window);
	                                        }
	                                    } else if (data.state === 'fail') {
	    				    				art.dialog({   
	    				    					content: data.info,
	    				    					icon: 'warning',  
	    				    					ok: function () {   
	    				    						this.title(data.info);   
	    				    						return true;   
	    				    					}
	    				    				}); 
	                                    }
	                                });
	                                return true;
	                            },
	                            cancelVal: '关闭',
	                            cancel: true
	                        });
	                    },
	                    cancelVal: '关闭',
	                    cancel: true
	                });
	            }
	        });
		});
		
		$('.set_status').click(function(e){
			e.preventDefault();
			$_this = this;
			var live_id = $($_this).attr('data-id');
			var status = $($_this).attr('data-status');
			
			var href = $($_this).prop('href');
			
			var contentHtml = "<select id='update_status' style='width:180px;'><option value='0'>--请选择--</option>";
			
			if(2 == status){
				contentHtml += "<option value='4' id='status_option_4'>正在直播</option><option value='5' id='status_option_5'>直播回顾</option>";
			}else if(4 == status){
				contentHtml += "<option value='2' id='status_option_2'>直播结束</option><option value='5' id='status_option_5'>直播回顾</option>";
			}else{
				contentHtml += "<option value='4' id='status_option_4'>正在直播</option><option value='2' id='status_option_2'>直播结束</option>";
			}
        	contentHtml += "</select>";
        	
			art.dialog({
                title: "更新状态",
                icon: '',
                content: contentHtml,
                close: function () {
                    $_this.focus(); //关闭时让触发弹窗的元素获取焦点
                    return true;
                },
                okVal:"确定",
                ok: function () {
                	var update_status = $('#update_status').val();
                	if(update_status == 0){
                		layer.msg('请选择直播状态！');
                		return false;
                	}
                	var status_text = $('#status_option_'+update_status).text();
                	art.dialog({
                        title: false,
                        icon: 'question',
                        content: '您确定要将直播状态设置为【' + status_text +'】吗？',
                        close: function () {
                        },
                        okVal:"确定",
                        ok: function () {
                        	$.getJSON(href+'&live_id=' + live_id+'&status='+update_status).done(function (data) {
                                if (data.state === 'success') {
                                    if (data.referer) {
                                        location.href = data.referer;
                                    } else {
                                        reloadPage(window);
                                    }
                                } else if (data.state === 'fail') {
				    				art.dialog({   
				    					content: data.info,
				    					icon: 'warning',  
				    					ok: function () {   
				    						this.title(data.info);   
				    						return true;   
				    					}
				    				}); 
                                }
                            });
                            return true;
                        },
                        cancelVal: '关闭',
                        cancel: true
                    });
                },
                cancelVal: '关闭',
                cancel: true
            });
		});
		
		
	});
	
	function refresh_news(news_id){
	    $.post("<?php echo U('Admin/Live/refreshLiveTime')?>",{news_id:news_id}, function(result){
	        if(result >= 1){
	            var msg = '刷新成功';
	        }else{
	            var msg = '刷新失败';
	        }
	        alert(msg);
	        window.location.reload();
	    });
	}
	
	function update_live_count(type_id,type){
        if(type == 'live'){
            edit_column = $("#edit_weight_"+type_id).html();
            column_befor = $("#old_weight_"+type_id).val();//原权重值
            column  = $("#weight"+type_id).val(); //现权重值
            now_input_type = $("#weight" + type_id); //权重 ID
            now_edit_type  = $("#edit_weight_" + type_id);  //修改 按钮ID
			live_id = type_id;
        }

        if(edit_column == "修改"){
            //处理 同时存在多个input编辑问题
            $(".input_edit").attr("disabled", "disabled");
            $(".edit_sub").html("修改");

            now_input_type.removeAttr("disabled");
            now_edit_type.html("确认");
        }else{
            if(column_befor == name){
                now_input_type.attr("disabled", "disabled");
                now_edit_type.html("修改");
            }else {
				$.ajax({  
					type: "POST",  
					cache: false,  
					data: "type="+type+"&live_id="+live_id+"&old_val="+column_befor+"&val="+column,  
					async: false,
					url: "{:U('Live/editLiveCount')}",  
					success: function(ret) {
						if(ret['code'] == 200){
							now_input_type.attr("disabled", "disabled");
							now_edit_type.html("修改");
							location.reload()
						}else{
							alert(ret.msg)
						}
					}, error: function(data) {  
						alert('网络错误，请稍后再试！');
					}  
				}); 
            }
        }
    }
	
	function update_weight(news_id){
        edit_column = $("#live_edit_weight_"+news_id).html();
        column_befor = $("#live_old_weight_"+news_id).val();//原权重值
        column  = $("#live_weight"+news_id).val(); //现权重值
        now_input_type = $("#live_weight" + news_id); //权重 ID
        now_edit_type  = $("#live_edit_weight_" + news_id);  //修改 按钮ID
        
        if(edit_column == "修改"){
            //处理 同时存在多个input编辑问题
            $(".live_input_edit").attr("disabled", "disabled");
            $(".live_edit_sub").html("修改");
          
            now_input_type.removeAttr("disabled");
            now_edit_type.html("确认");
        }else{
            if(column_befor == column){
                now_input_type.attr("disabled", "disabled");
                now_edit_type.html("修改");
            }else {
                $.post("{:U('Live/changeWeight')}", {weight: column, live_id: news_id},
                        function (result) {
                            if (result == 1) {
                                now_input_type.attr("disabled", "disabled");
                                now_edit_type.html("修改");
                                location.reload()
                            }else{
                                alert("异常!")
                            }
                        }
                );
            }
        }
        $("#live_weight"+news_id).removeAttr("disabled");
    }
	
	</script>
</body>
</html>